package com.yic.module.base.dal.mysql.supplier;

import java.util.*;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.base.dal.dataobject.brand.BrandDO;
import com.yic.module.base.dal.dataobject.supplier.SupplierDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.base.controller.admin.supplier.vo.*;

/**
 * 供应商信息 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface SupplierMapper extends BaseMapperX<SupplierDO> {

    default PageResult<SupplierDO> selectPage(SupplierPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SupplierDO>()
                .likeIfPresent(SupplierDO::getName, reqVO.getName())
                .likeIfPresent(SupplierDO::getCode, reqVO.getCode())
                .likeIfPresent(SupplierDO::getSocietyCode, reqVO.getSocietyCode())
                .eqIfPresent(SupplierDO::getReputation, reqVO.getReputation())
                .eqIfPresent(SupplierDO::getStatus, reqVO.getStatus())
                .orderByDesc(SupplierDO::getId));
    }

    default List<SupplierDO> selectList(SupplierExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<SupplierDO>()
                .likeIfPresent(SupplierDO::getName, reqVO.getName())
                .likeIfPresent(SupplierDO::getCode, reqVO.getCode())
                .likeIfPresent(SupplierDO::getSocietyCode, reqVO.getSocietyCode())
                .eqIfPresent(SupplierDO::getReputation, reqVO.getReputation())
                .eqIfPresent(SupplierDO::getStatus, reqVO.getStatus())
                .orderByDesc(SupplierDO::getId));
    }

    default SupplierDO selectByName(String name) {
        return selectOne(new LambdaQueryWrapperX<SupplierDO>()
                .eq(SupplierDO::getName, name));
    }

    default SupplierDO selectByCode(String code) {
        return selectOne(new LambdaQueryWrapperX<SupplierDO>()
                .eq(SupplierDO::getCode, code));
    }

    default List<SupplierDO> selectList(Collection<Long> ids, Collection<Integer> statuses) {
        return selectList(new LambdaQueryWrapperX<SupplierDO>()
                .inIfPresent(SupplierDO::getId, ids)
                .inIfPresent(SupplierDO::getStatus, statuses));
    }
}
